package com.yjtc.cbg.commonutildemo;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.yjtc.cbg.commonutildemo.Util.HttpUtil;
import com.yjtc.cbg.commonutildemo.Util.SelectorDrawableUtil;


public class MainActivity extends AppCompatActivity {

    private static final int REQUEST_QR_CODE = 1000;
    private int textColor=0;
    private Button mButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv = (TextView) findViewById(R.id.id_text);
        mButton= (Button) findViewById(R.id.button);
        mButton.setBackground(SelectorDrawableUtil.getSelector(SelectorDrawableUtil.getNormalDrawable(MainActivity.this,10, Color.CYAN,2,Color.RED),SelectorDrawableUtil.getNormalDrawable(MainActivity.this,10, Color.WHITE,2,Color.BLUE)));
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    HttpUtil httpUtil = new HttpUtil(MainActivity.this);
                    httpUtil.getdata();
                }catch (Exception e){
                    e.printStackTrace();
                }

            }
        });
        SpannableStringBuilder ssb = new SpannableStringBuilder();
        textColor = getResources().getColor(R.color.blue);
        SpannableString spannableString = new SpannableString("how are you");
        spannableString.setSpan(new ForegroundColorSpan(textColor),0,spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
            }

            @Override
            public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
            }
        },0,spannableString.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssb.append(spannableString);
        tv.setText(ssb);
        tv.setMovementMethod(LinkMovementMethod.getInstance());

//
//        Observable<String> observable=Observable.create(new Subscriber<String>() {
//            @Override
//            public void onCompleted() {
//
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onNext(String s) {
//
//            }
//        });

//       observable.subscribe(new Subscriber() {
//           @Override
//           public void onCompleted() {
//
//           }
//
//           @Override
//           public void onError(Throwable e) {
//
//           }
//
//           @Override
//           public void onNext(Object o) {
//
//           }
//       });



    }


    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK
                && requestCode == REQUEST_QR_CODE
                && data != null) {
            String result = data.getStringExtra("result");
            Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
        }
    }

}
